package com.healthy_software.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private Boolean success;
    private String errorMsg;
    private Object data;
    private Long total;
    private Integer code;
    private String message;

    public static Result ok(){
        return new Result(true, null, null, null, 200, null);
    }

    public static Result ok(Object data){
        return new Result(true, null, data, null, 200, null);
    }

    public static Result ok(String message ,Object data){
        return new Result(true, null, data, null, 200, message);
    }

    public static Result ok(String message){
        return new Result(true, null, null, null, 200, message);
    }

    public static Result ok(List<?> data, Long total){
        return new Result(true, null, data, total, 200, null);
    }

    public static Result fail(String errorMsg){
        return new Result(false, errorMsg, null, null, null, null);
    }

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String message) {
        Result result = new Result();
        result.message = message;
        result.code = 0;
        return result;
    }
}
